package cn.gdrj.est.util;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
@ConfigurationProperties(prefix = "oauth2.wechat")
public class WechatLoginProperties {
    private String appId;
    private String appSecret;
    private String codeUrl;
    private String accessTokenUrl;
    private String redirectUrl;
    private String userInfoUrl;
    private String loginSuccessUrl;

    public String getFullCodeUrl(){
        StringBuilder builder= new StringBuilder(codeUrl);
        builder.append("appid=").append(appId);
        builder.append("&redirect_uri=").append(redirectUrl);
        builder.append("&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect");
        return builder.toString();
    }

    public String getFullAccessTokenURL(String code) {
        StringBuilder builder= new StringBuilder(accessTokenUrl);
        builder.append("appid=").append(appId);
        builder.append("&secret=").append(appSecret);
        builder.append("&code=").append(code);
        builder.append("&grant_type=authorization_code");
        return builder.toString();
    }

    public String getFullUserInfoURL(String accessToken, String openid) {
        StringBuilder builder= new StringBuilder(userInfoUrl);
        builder.append("access_token=").append(accessToken);
        builder.append("&openid=").append(openid);
        return builder.toString();
    }
}
